package com.iris.live.services.controllers;

import com.iris.live.services.models.PageData;
import com.iris.live.services.models.ResultData;
import com.iris.live.services.services.MgtReportService;
import com.iris.live.services.services.ReportService;
import com.iris.live.services.vo.report.MarketIntegratedVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * Created by HangLiu on 2017/8/9.
 */
@RestController
@RequestMapping("/mgtReport")
public class MgtReportController {
    private static Logger log = LoggerFactory.getLogger(MgtReportController.class);

    @Autowired
    private MgtReportService mgtReportService;

    @Autowired
    private ReportService reportService;

    /**
     * 销售管理报表
     * @param re
     * @return
     */
    @RequestMapping(value = "/getSalesReportInfo", method = RequestMethod.POST)
    public List getSalesReport( HttpServletRequest re,@RequestBody Map info) {
        try{
            return mgtReportService.getSalesReport(info);
        }
        catch (Exception e){
            log.error("销售管理报表数据获取异常",e);
            return  null;
        }
    }

    /**
     * 金融管理报表
     * @param re
     * @return
     */
    @RequestMapping(value = "/getFinanceReport", method = RequestMethod.POST)
    public List getFinanceReport( HttpServletRequest re ,@RequestBody Map info) {
        try{
            return  mgtReportService.getFinanceReport(info);
        }
        catch (Exception e){
            log.error("金融管理报表数据获取异常",e);
            return  null;
        }
    }

    /**
     * 保险管理报表
     * @param re
     * @return
     */
    @RequestMapping(value = "/getInsReport", method = RequestMethod.POST)
    public List getInsReport( HttpServletRequest re ,@RequestBody Map info){
        try{
            return  mgtReportService.getInsReport(info);
        }
        catch (Exception e){
            log.error("保险管理报表数据获取异常",e);
            return  null;
        }
    }

    /**
     * 金融漏斗报表
     * @param re
     * @return
     */
    @RequestMapping(value = "/getFinanceAnalyticalRpt", method = RequestMethod.POST)
    public List getFinanceFunnel( HttpServletRequest re ,@RequestBody Map info){
        try{
            return  mgtReportService.getFinanceFunnel(info);
        }
        catch (Exception e){
            log.error("金融漏斗报表获取异常",e);
            return  null;
        }
    }

    /**
     * 销售漏斗报表
     * @param re
     * @return
     */
    @RequestMapping(value = "/getSaleAnalyticalRpt", method = RequestMethod.POST)
    public List getSalesFunnel( HttpServletRequest re ,@RequestBody Map info){
        try{
            return  mgtReportService.getSalesFunnel(info);
        }
        catch (Exception e){
            log.error("销售漏斗报表获取异常",e);
            return  null;
        }
    }

    /**
     * 保险战败原因分析
     * @param re
     * @return
     */
    @RequestMapping(value = "/getInsDefeatedResonRpt", method = RequestMethod.POST)
    public List getInsDefeatedResonRpt( HttpServletRequest re,@RequestBody Map info ){
        try{
            return  mgtReportService.getInsDefeatedResonRpt(info);
        }
        catch (Exception e){
            log.error("保险战败原因分析报销获取异常",e);
            return  null;
        }
    }

    /**
     * 金融战败原因分析
     * @param re
     * @return
     */
    @RequestMapping(value = "/getFinDefeatedResonRpt", method = RequestMethod.POST)
    public List getFinDefeatedResonRpt( HttpServletRequest re ,@RequestBody Map info){
        try{

            return  mgtReportService.getFinDefeatedResonRpt(info);
        }
        catch (Exception e){
            log.error("金融管理报表数据获取异常",e);
            return  null;
        }
    }


    /**
     * DCC渠道线索统计(报表)
     * @param re
     * @return
     */
    @RequestMapping(value = "/getDCCChannelClue",method = RequestMethod.POST)
    public List getDCCChannelClue(HttpServletRequest re,@RequestBody Map info){
        try {
            return mgtReportService.getDCCChannelClue(info);
        }catch (Exception e){
            log.error("DCC渠道线索报表获取异常",e);
            return null;
        }
    }

    /**
     * 后市场业务报告(报表)
     * @param re
     * @return
     */
    @RequestMapping(value = "/getAfterMarketBusiness",method = RequestMethod.POST)
    public List getAfterMarketBusiness(HttpServletRequest re,@RequestBody Map info){
        try {
            return mgtReportService.getAfterMarketBusiness(info);
        }catch (Exception e){
            log.error("后市场业务报告(报表)获取异常",e);
            return null;
        }
    }


    /**
     * 后市场产品加装率报告(报表)
     * @param re
     * @return
     */
    @RequestMapping(value = "/getAfterMarketProductInstallation",method = RequestMethod.POST)
    public List getAfterMarketProductInstallation(HttpServletRequest re,@RequestBody Map info){
        try {
            return mgtReportService.getAfterMarketProductInstallation(info);
        }catch (Exception e){
            e.printStackTrace();
            log.error("后市场产品加装率报告(报表)获取异常",e);
            return null;
        }
    }

    @RequestMapping(value = "/getFenjie",method = RequestMethod.POST)
    public List getFenjie(HttpServletRequest re,@RequestBody Map info){
        try {
            return mgtReportService.getSaleGoal(info);
        }catch (Exception e){
            log.error("销售目标分解",e);
            return null;
        }
    }

    /**
     * 库存预测(报表)
     * @param re
     * @param info
     * @return
     */
    @RequestMapping(value = "/getStockForecast",method = RequestMethod.POST)
    public Map getStockForecast(HttpServletRequest re,@RequestBody Map info){
        try {
            return mgtReportService.getStockForecast(info);
        }catch (Exception e){
            log.error("库存预测报表异常",e);
            return null;
        }
    }

    /**
     * 采购预测导出全部品牌(报表)
     * @param re
     * @param info
     * @return
     */
    @RequestMapping(value = "/getBuildPurchaseReportAll",method = RequestMethod.POST)
    public List getBuildPurchaseReportAll(HttpServletRequest re,@RequestBody Map info){
        try {
            return mgtReportService.getBuildPurchaseReportAll(info);
        }catch (Exception e){
            log.error("库存预测报表异常",e);
            return null;
        }
    }

    /**
     * CRM调研报告(报表)
     * @param re
     * @return
     */
    @RequestMapping(value = "/getCRMSurveyReport",method = RequestMethod.POST)
    public List getCRMSurveyReport(HttpServletRequest re,@RequestBody Map info){
        try {
            return mgtReportService.getCRMSurveyReport(info);
        }catch (Exception e){
            log.error("CRM调研报告报表获取异常",e);
            return null;
        }
    }

    /**
     *市场月度报告 显示接口
     * @param info
     * @return
     */
    @RequestMapping(value = "/getMarketIntegratedReport",method = RequestMethod.POST)
     public List getMarketIntegratedReport(@RequestBody Map info){
        try {
            return mgtReportService.getMarketIntegratedReport(info);
        }catch (Exception e){
            log.error("市场月度报告",e);
            return null;
        }
    }

    /**
     * 市场月度报表 填报接口
     * @param infoList
     * @return
     */
    @RequestMapping(value = "/updateMarketIntegrated/{permit}/{year}",method=RequestMethod.POST)
    public ResultData  updateMarketIntegrated(@RequestBody List <MarketIntegratedVO> infoList,@PathVariable String permit,@PathVariable String year){
        return mgtReportService.updateMarketIntegrated(infoList,permit,year);
    }


    /**
     * 销售毛利预测
     * @param re
     * @param info
     * @return
     */
    @RequestMapping(value = "/getGrossProfitForecastReport",method = RequestMethod.POST)
    public List getGrossProfitForecastReport(HttpServletRequest re,@RequestBody Map info){
        try {
            return mgtReportService.getCRMSurveyReport(info);
        }catch (Exception e){
            e.printStackTrace();
            log.error("销售毛利预测报表获取异常",e);
            return null;
        }
    }

    /**
     *金融服务费追踪
     * @param reportVo
     * @return
     */
    @RequestMapping(value = "/getFinancialServiceFeeRateReport",method = RequestMethod.POST)
    public List getFinancialServiceFeeRateReport(@RequestBody MgtReportService.FinancialServiceFeeRateReport reportVo){
        try {
            return mgtReportService.getFinancialServiceFeeRateReport(reportVo);
        }catch (Exception e){
            e.printStackTrace();
            log.error("金融服务费追踪获取异常",e);
            return null;
        }
    }

    /**
     * 销售财务报表
     * @param info
     * @return
     */
    @RequestMapping(value = "/getSalesFinanceReoprt", method = RequestMethod.POST)
    public List getSalesFinanceReoprt(@RequestBody Map info){
        try {
            return mgtReportService.getSalesFinanceReoprt(info);
        } catch (Exception e) {
            log.error("销售财务报表获取异常", e);
            return null;
        }
    }

    /**
     * 保险合作机构汇总报表
     * @param info
     * @return
     */
    @RequestMapping(value = "/getInsuranceSummary",method = RequestMethod.POST)
    public List getInsuranceSummary(@RequestBody Map info){
        try {
            return mgtReportService.getInsuranceSummary(info);
        }catch (Exception e){
            e.printStackTrace();
            log.error("保险合作机构汇总报表获取异常", e);
            return null;
        }
    }


    /**
     * 展厅客流日志 查询 --提供给 帆软
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/flowInfo", method = RequestMethod.POST)
    public ResultData flowInfo(@RequestBody Map map) {
        ResultData resultData = new ResultData("false", null, null);
        try {
            resultData = reportService.findFlowInfo(map);
        } catch (Exception e) {
            log.error("展厅客流日志 查询程序异常", e);
        }
        return resultData;
    }

    /**
     * 展厅客流日志 线索数 查询 --提供给 帆软
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/flowClueNum", method = RequestMethod.POST)
    public Map flowClueNum(@RequestBody Map params) {
        Map map = null;
        try {
            map = reportService.flowClueNum(params);
        } catch (Exception e) {
            log.error("展厅客流日志 线索数 查询程序异常");
        }
        return map;
    }

    /**
     * 线索跟进 --提供给 帆软
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getShowFlowupReport", method = RequestMethod.POST)
    public List getShowFlowupReport(@RequestBody ReportService.ShowFlowupReportVO params,
                                    HttpServletResponse response) {
        return reportService.getShowFlowupReport(params.username, params.dealer,  params.startTime, params.endTime, response);
    }

    /**
     * 销售日报
     * @param info
     * @return
     */
    @RequestMapping(value = "/getSalesDailyReport", method = RequestMethod.POST)
    public List getSalesDailyReport (@RequestBody Map info) {
        try {
            return mgtReportService.getSalesDailyReport(info);
        } catch (Exception e) {
            log.error("销售日报获取异常", e);
            return null;
        }
    }

    /**
     * 市场活动报表
     * @param info
     * @return
     */
    @RequestMapping(value = "/getMargetingActivityReoprt", method = RequestMethod.POST)
    public PageData getMargetingActivityReoprt (@RequestBody Map info) {
        try {
            return mgtReportService.getMargetingActivityReoprt(info);
        } catch (Exception e) {
            log.error("市场活动列表报表获取异常", e);
            return null;
        }
    }

}
